class MaintainItemsController < ApplicationController
  before_action :set_menu

  def new
    @maintain_item = MaintainItem.new
  end

  def create
    @maintain_item = MaintainItem.new post_params
    if @maintain_item.save
       redirect_to maintain_style_path(:id =>@maintain_item.maintain_style.id)
    else
      render :action => 'new'
    end
  end

  def destroy
    @maintain_item = MaintainItem.find params[:id]
    @maintain_item.destroy
    redirect_to maintain_style_path(:id =>@maintain_item.maintain_style.id)
  end

   def post_params
    params.require(:maintain_item).permit(*%w(maintain_style_id name amount working_hour))
  end

  private
  def set_menu
    @mainmenu = :base_data
  end
end
